//
//  PayModel.m
//  CloudTest
//
//  Created by 张帅 on 2020/7/30.
//  Copyright © 2020 张帅. All rights reserved.
//

#import "PayModel.h"

@implementation PayModel

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    static PayModel *instance = nil;
    dispatch_once(&onceToken,^{
        instance = [[super allocWithZone:NULL] init];
    });
    return instance;
}
- (instancetype)init {
    self = [super init];
    if (self) {
        _is_pay = NO;
    }
    return self;
}

#pragma mark 模拟支付
+ (void)moni_paly_orderNo:(NSString *)orderNo success:(ObjSuccess)successBlock error:(ErrorBlock)errorBlock {
    NSString *url = [NSString stringWithFormat:@"%@orderNo=%@",moni_paly_url,orderNo];
      [NetWorkTools requestWithURLStr:url method:GET params:nil success:^(id responseObject) {
          GDLog(@"模拟支付 %@",responseObject);
          if ([AppTools isStateSuccess:responseObject]) {
                 if (successBlock) {
                     successBlock(nil);
                 }
             } else {
                 if (errorBlock) {
                    errorBlock();
                }
             }
      } failure:^(NSError *error) {
          if (errorBlock) {
              errorBlock();
          }
          NSString *errorStr = [self errorDescribe:error];
          [QMUITips showError:errorStr];
      }];
}

/// 验证支付是否完成
/// @param orderId 订单id
/// @param successBlock successBlock
/// @param errorBlock errorBlock
+ (void)validation_order_isPay_orderId:(NSString *)orderId success:(ObjSuccess)successBlock error:(ErrorBlock)errorBlock {
    NSString *url = [NSString stringWithFormat:@"%@orderId=%@",validation_order_isPay_url,orderId];
     [NetWorkTools requestWithURLStr:url method:GET params:nil success:^(id responseObject) {
         GDLog(@"是否支付完成 %@",responseObject);
         if ([AppTools isStateSuccess:responseObject]) {
             PayModel * model =[PayModel yy_modelWithJSON:responseObject[@"data"]];
                 if ([model.value intValue] == 2) {
                     model.is_pay = YES;//翼支付
                 }
                if (successBlock) {
                    successBlock(model);
                }
            } else {
                if (errorBlock) {
                       errorBlock();
                   }
            }
     } failure:^(NSError *error) {
         if (errorBlock) {
             errorBlock();
         }
         NSString *errorStr = [self errorDescribe:error];
         [QMUITips showError:errorStr];
     }];
}

@end
